﻿import mx.utils.*;
import mx.transitions.*;
import mx.transitions.easing.*;
import com.dmotiko.general.*;
import com.dmotiko.lib.*;
import com.dmotiko.prune.*;
/**
 * ...
 * @author sminutoli
 */
class com.dmotiko.prune.NewsContainer extends BaseClip
{
	private var clip_showed_listener:Function;
	
	private var mcScroll:MovieClip;
	private var mcContent:MovieClip;
	
	private var aClips:Array;
	private var nClip:Number;
	private var nY:Number;
	
	private function initClip():Void {
		//System.useCodepage = true;
		//NewsLoader.run("news.xml", this);
		NewsLoader.run("http://www.prune.com.ar/getnews.php", this);
		
		clip_showed_listener = Delegate.create(this, clip_showed);
		mcContent = mcScroll.createEmptyMovieClip( "mcContent", mcScroll.mcContent ? mcScroll.mcContent.getDepth() : mcScroll.getNextHighestDepth() );
		mcContent._x = mcScroll.mcMask._x;
		mcContent._y = mcScroll.mcMask._y;
		
		mcScroll.mcDrag._btnup = mcScroll.mcUp;
		mcScroll.mcDrag._btndown = mcScroll.mcDown;
		ScrollerMovie.setScroll( mcScroll.mcContent, mcScroll.mcMask, mcScroll.mcDrag, mcScroll.mcBar );
	}

	private function refreshData(){
					
		var header:MovieClip = this.attachMovie( "NewsHeader", "newsHeader", this.getNextHighestDepth());
		header.show();
		
		aClips = new Array();
		nClip = 0;
		nY = 0;
		
		for( var i=0; i < data.length; i++){
			var clip:MovieClip = mcContent.attachMovie( "NewItem", "NewItem"+i, mcContent.getNextHighestDepth());
			clip._y = nY;
			clip.nClip = i;
			clip.addEventListener( BaseClipEvent.SHOW_END, clip_showed_listener);
			clip.setData(data[i]);
			nY += clip._height + 5;
			aClips.push(clip);
			if( i == 0 ){
				clip.show();
			}
		}
		
	}

	private function clip_showed(e):Void {
		if( aClips[ e.target.nClip + 1 ] ){
			aClips[ e.target.nClip + 1 ].show();
		}
	}
	
}